package com.sxz.sbs.util;


import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 日期工具类
 */

public class DateUtils {
    /**
     * 判断是否是当月
     * @param date
     * @return
     */
    public static boolean isSameMonth(final Date date) {
        return isSameTime(date.getTime(),"yyyy-MM");
    }
    private static boolean isSameTime(long time,String pattern) {
        Date date = new Date(time);
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        String param = sdf.format(date);
        String now = sdf.format(new Date());
        if(param.equals(now)){
            return true;
        }
        return false;
    }

    /**
     * 获取下个月一号
     * @return
     */
    public static Date nextMonthFirstDate(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MONTH, 1);
        return calendar.getTime();
    }
}
